<!--
* description: 网点打款账号维护
* author: 陈苇林
* createdDate: 2021-08-12
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-show-more-btn="true"
      :dynamic-api-style="'restful'"
      :dynamic-page-size="10"
      :page-size-array="[10, 20, 30, 50]"
    >
    </one-table-template>
    <edit
      ref="outletEdit"
      :diaLogVisible.sync="EditVisible"
      :OpenMode="OpenMode"
      :id="DialogId"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/pa/apiBaseData'
import { orgApis } from '@/api/pabasicdataapi'
import { exportExcel } from '@/utils/getTimeString.js'
import Vue from 'vue'

export default {
  name: 'PricePartsExamine',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  filters: {
    // 小数转换百分比显示
    percentage: function(num) {
      if (!num) return ''
      return (Number(num) * 100).toFixed(2) + '%'
    },
    fixTwo: function(val) {
      return Number(val).toFixed(2)
    }
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next(vm => { vm.queryTable(1) })
    })
  },
  created(){
      const that = this 
    //   this.$set(that.formField,'dlrName',that.$store.state.user.orgInfo.DLR_NAME)
    //   this.$set(that.formField,'dlrCode',that.$store.state.user.orgInfo.DLR_ID)
      
    this.formField.dlrName = this.$store.state.user.orgInfo.DLR_NAME
    this.formField.dlrCode = this.$store.state.user.orgInfo.DLR_CODE
  },
  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      icon: 'el-icon-arrow-down',
      //dialog打开方式   
      OpenMode:null,
      //dialog  ID
      DialogId:null,
      selectiondata: [],
      // 网格查询API配置对象
      apiConfig: api.queryAddSparePartReviewList,
      EditVisible:false,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey10',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey20',
          type: '',
          size: 'small',
          clickEvent: () => this.add('add'),
          text: '新增', // 新增
          name: 'add',
          position: 'right'
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          text: '导出',
          name: 'export',
          position: 'right'
        },
        {
          compKey: 'btnKey30',
          type: '',
          size: 'small',    
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }     
      ],

      // 动态组件-查询条件
      tableComponents:
        [
            {
              compKey: 'compKey10',
              labelName: '网点编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled:true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey20',
              labelName: '网点名称：',
              codeField: 'dlrName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled:true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey30',
              labelName: '打款账号：',
              codeField: 'partRepairType',
              textField: 'partRepairTypeName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey40',
              labelName: '启用状态',
              codeField: 'replacePiece',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '是' },
                { statusId: '0', statusText: '否' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: true,
              span: 6
            },            
            {
              compKey: 'compKey50',
              labelName: '创建日期',
              codeField: 'beginDate,endDate',
              component: () => import('@/components/org/datePicker/andtDatePicker'),
              type: 'YYYY-MM-DD',
              format: 'yyyy-MM-dd',
              dateOptionsType: '0',
              isMul: false,
              isMust: true
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
                {
            prop: 'controlBtn1',
            label: '操作',
            isComponent: true,
            fixed: true,
            comps: [
                {
                compKey: 'propKey1',
                labelName: '修改',
                component: () => import('@/components/org/linkButton'),
                clickEvent: (index,row) => this.add(index,row)
                }
            ]
            },
            {
              prop: 'partId',
              label: '网点编码',
              hidden: false,
            },
            {
              prop: 'partPriceId',
              label: '网点名称',
              hidden: false,
            },
            {
              prop: 'partPriceReviewId',
              label: '打款账号',
              hidden: false,
            },
            {
              prop: 'updateControlId',
              label: '账户名',
              hidden: false,
            },
            {
              prop: 'reviewStatus',
              label: '开户行名称',
              hidden: false,
            },
            {
              prop: 'isEnable',
              label: '创建人',
              hidden: false,
            },
            {
              prop: 'partNo',
              label: '创建时间'
            },
            {
              prop: 'partName',
              label: '启用状态'
            },
            {
              prop: 'costPrice',
              label: '备注'
            }
          ],
      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          dlrName:'123',
          dlrCode:'',
          partRepairType: '',
          partNameCn: '',
          partStatus: '',
          supplierCode: '',
          partNo: '',
          partName: '',
          carConfigCn: '',
          carConfigIdList: '',
          replacePiece: '',
          reviewStatus: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },

  methods: {
    exportExcel111() {
      exportExcel(this.formField, api.exportRejectSparePartPrice.APIUrl, api.exportRejectSparePartPrice.ServiceCode, '备件价格新增审核')
    },
    onCheckSelectChange1(selection) {
      var btn1 = this.tableButtons[2]
      var btn2 = this.tableButtons[3]
      const isCheck = selection && selection.length > 0
      btn1.disabled = !isCheck
      btn2.disabled = !isCheck
    },
    // 批量驳回、通过
    add(val) {
        const index = Number(val)
        if(isNaN(index)){
          this.OpenMode = 'add'
          this.DialogId = null 
        } else {
          this.OpenMode = 'edit'
          this.DialogId = this.$refs.multipleTable.list[index].id
        }
        this.EditVisible = true 
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
